package com.aacar.controller.common;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.aacar.dto.AreaDto;
import com.aacar.dto.CityDto;
import com.aacar.dto.Header;
import com.aacar.service.AreaSerivce;
import com.aacar.utils.ResultInfoUtil;
import com.aacar.vo.AreaVo;
import com.aacar.vo.CityVo;
import com.aacar.vo.ProvinceVo;
import com.aacar.vo.RoomNameVo;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;

/**
 * 地址controller
 * @author wangh
 *
 */
@RestController
@RequestMapping("/area")
public class AreaController {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private AreaSerivce areaSerivce;//区域服务
	
	//获取所有省份
	@RequestMapping(value = "/getProvinceList/0", method = RequestMethod.POST)
    @ResponseBody
	public Object getProvinceList(@RequestHeader(value="mobilehead") String mobilehead) {
		logger.info("request:/getProvinceList/0");
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		List<ProvinceVo> pv = this.areaSerivce.getProvinceList(null);
		Map<String,Object> map = Maps.newConcurrentMap();
		map.put("info", pv);
		return ResultInfoUtil.setSuccessInfo(map,header.getService());
	}
	
	//获取所有城市
	@RequestMapping(value = "/getCityList/0", method = RequestMethod.POST)
    @ResponseBody
	public Object getCityList(@RequestHeader(value="mobilehead") String mobilehead,@RequestBody CityDto cityDto) {
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		List<CityVo> cityVo = this.areaSerivce.getCityList(cityDto);
		Map<String,Object> map = Maps.newConcurrentMap();
		map.put("info", cityVo);
		return ResultInfoUtil.setSuccessInfo(map,header.getService());
	} 
	
	//获取所有区
	@RequestMapping(value = "/getAreaList/0", method = RequestMethod.POST)
    @ResponseBody
	public Object getAreaList(@RequestHeader(value="mobilehead") String mobilehead,@RequestBody AreaDto areaDto) {
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		List<AreaVo> areaVo = this.areaSerivce.getAreaList(areaDto);
		Map<String,Object> map = Maps.newConcurrentMap();
		map.put("info", areaVo);
		return ResultInfoUtil.setSuccessInfo(map,header.getService());
	} 
	
	
	//获取所有的省市区小区名字
	@RequestMapping(value = "/getRoomName/0", method = RequestMethod.POST)
    @ResponseBody
	public Object getRoomName(@RequestHeader(value="mobilehead") String mobilehead,@RequestBody AreaDto areaDto) {
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		List<RoomNameVo> roomName = this.areaSerivce.getAreaRoomList();
		Map<String,Object> map = Maps.newConcurrentMap();
		map.put("info", roomName);
		return ResultInfoUtil.setSuccessInfo(map,header.getService());
	} 
	
	
	
	

}
